<template>
	<view class="vip">
		<view class="vipbox">
			<view :class="isactive?'vipitem active':'vipitem'" @click="changeA(1)">
				<text class="name">月会员</text>
				<text class="price">￥ {{data.month_vip}}</text>
			</view>
			<view :class="isactive?'vipitem ':'vipitem active'" @click="changeA(2)">
				<text class="name">年会员</text>
				<text class="price">￥ {{data.year_vip}}</text>
			</view>
		</view>
		<view class="charge_1">
			<text class="title">选择支付方式</text>
			<view class="charge_check">
				<view class="left">
					<image src="/static/index/yh.png" mode=""></image>
					<view class="text">
						<text>余额支付</text>
						<!-- <text class="num">￥980</text> -->
					</view>
				</view>
				<view class="right">
					<label>
						<checkbox checked disabled />
					</label>
				</view>
			</view>
		</view>
		<view class="btn" @click="pay">
			立即购买
		</view>
		<view class="bg" v-if="isSure">
			<view class="password">
				<view class="title">
					<text>请输入支付密码</text>
					<text @click="close">X</text>
				</view>
				<view class="password_input">
					<input type="password" v-model="password" placeholder="请输入支付密码"
						placeholder-style="font-size:14px;color:#777" />
				</view>
				<view class="getbtn">
					<view class="btn1" @click="sure">
						确认
					</view>
					<view class="btn2" @click="close">
						取消
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		SureBuy,
		BuyVip
	} from '../../api/user.js'
	export default {
		data() {
			return {
				isactive: true,
				data: [],
				type: 1,
				isSure: false,
				password: ''
			}
		},
		onLoad() {
			this.BuyVip()
		},
		methods: {
			close() {
				this.isSure = false
				this.password = ''
			},
			pay() {
				this.isSure = true
			},
			BuyVip() {
				BuyVip().then(res => {
					console.log(res)
					this.data = res.data
				})
			},
			sure() {

				if (this.password == '') {
					uni.showToast({
						title: '请输入支付密码',
						icon: 'none'
					})
				} else {
					this.SureBuy()
				}

			},
			SureBuy() {
				SureBuy({
					password: this.password,
					type: this.type,
					pay_type: 4
				}).then(res => {
					console.log(res)
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
					this.isSure = false
					this.password = ''
					setTimeout(() => {
						if (res.status == 1) {
							uni.switchTab({
								url: '/pages/user/index'
							})
						}
					}, 1000)

				})
			},
			changeA(i) {
				this.type = i
				if (i == 1) {
					this.isactive = true
				} else {
					this.isactive = false
				}
			}
		}
	}
</script>

<style lang="scss">
	.vip {
		background: #1d3f2b;
		height: calc(100vh - 44px);
		font-size: 16px;

		.vipbox {
			display: flex;
			padding: 5%;

			.vipitem {
				display: flex;
				color: #4e6959;
				flex-direction: column;
				border: 1px solid #4e6959;
				border-radius: 8px;
				color: #949494;
				width: 45%;
				margin: 0 2.5%;
				text-align: center;
				height: 380rpx;


				.name {
					margin-top: 40px;
				}

				.price {
					margin-top: 10px;
					font-size: 14px;
				}
			}

			.active {
				border: 1px solid #fff;
				color: #fff;
			}

		}

		.btn {
			border: 1px solid;
			margin-top: 30px;
		}

		.charge_1 {
			padding: 10px 5%;
			width: 80%;
			margin: 0 auto;
			margin-top: 8px;
			border-radius: 5px;
			background: #fff;

			.title {
				font-size: 14px;
			}

			.payimg {
				padding: 10px 0;

				image {
					width: 90%;
					margin-left: 5%;
				}
			}

			.charge_check {
				border-top: 1px solid #1d3f2b;
				margin-top: 10px;
				padding: 10px 10px;
				display: flex;
				justify-content: space-between;
				align-items: center;

				.left {
					display: flex;
					align-items: center;

					image {
						width: 70rpx;
						height: 70rpx;
					}

					.text {
						display: flex;
						flex-direction: column;
						font-size: 12px;
						margin-left: 10px;

						.num {
							color: #777;
						}
					}
				}
			}
		}

	}

	.bg {
		background: #00000033;
		position: absolute;
		top: 0;
		width: 100%;
		height: 100%;

		.password {
			background: #fff;
			position: absolute;
			width: 90%;
			left: 5%;
			top: 60vw;

			.title {
				display: flex;
				justify-content: space-between;
				padding: 4% 5%;
				font-size: 28rpx;
				background: #f8f8f8;
			}

			.password_input {
				border: 1px solid #ccc;
				width: 70%;
				margin: 70rpx auto;

				input {
					padding-left: 40rpx;
					height: 80rpx;
				}
			}

			.getbtn {
				display: flex;
				justify-content: flex-end;
				margin-top: 170rpx;
				padding-bottom: 40rpx;

				view {
					padding: 10rpx 30rpx;
					font-size: 28rpx;
				}

				.btn1 {
					background: #1E9FFF;
					color: #fff;
				}

				.btn2 {
					border: 1px solid #ccc;
					color: #777;
					margin: 0 40rpx;
				}
			}

		}
	}
</style>
